Fourierov integral
Primjer snimanja signala, numeričkog računanja Fourierovog integrala, i rekonstrukcije signala nakon rezanja frekvencija.
xxxxxxxxxx6
1
begin2
using PortAudio, SampledSignals3
import LibSndFile4
using FileIO: load, save, loadstreaming, savestreaming, query5
# using QuadGK6
endxxxxxxxxxx1
1
# pkg> add https://github.com/JuliaAudio/PortAudio.jl.git"Microsoft Sound Mapper - Input"
"MME"
2
0
44100.0
0
0.09
0.09
0.18
0.18
"Microphone (BRIO 4K Stream Edit"
"MME"
2
0
44100.0
1
0.09
0.09
0.18
0.18
"Microphone Array (Realtek(R) Au"
"MME"
4
0
44100.0
2
0.09
0.09
0.18
0.18
"Microsoft Sound Mapper - Output"
"MME"
0
2
44100.0
3
0.09
0.09
0.18
0.18
"Speakers (Logitech Z337 Stereo)"
"MME"
0
2
44100.0
4
0.09
0.09
0.18
0.18
"E2351 (2- Intel(R) Display Audi"
"MME"
0
2
44100.0
5
0.09
0.09
0.18
0.18
"Microphone Array 1 (Realtek HD Audio Mic input with SST)"
"Windows WDM-KS"
2
0
48000.0
6
0.01
0.01
0.04
0.04
"Microphone Array 2 (Realtek HD Audio Mic input with SST)"
"Windows WDM-KS"
4
0
16000.0
7
0.01
0.01
0.04
0.04
"Microphone Array 3 (Realtek HD Audio Mic input with SST)"
"Windows WDM-KS"
4
0
16000.0
8
0.01
0.01
0.04
0.04
"Speakers (Realtek HD Audio output)"
"Windows WDM-KS"
0
8
44100.0
9
0.01
0.01
0.04
0.04
"Headphones ()"
"Windows WDM-KS"
0
2
44100.0
10
0.01
0.01
0.0853333
0.0853333
"Microphone (BRIO 4K Stream Edition)"
"Windows WDM-KS"
2
0
48000.0
11
0.01
0.01
0.0853333
0.0853333
"Output (Intel(R) Display Audio Output 1)"
"Windows WDM-KS"
0
2
44100.0
12
0.01
0.01
0.04
0.04
"Speakers ()"
"Windows WDM-KS"
0
2
44100.0
13
0.01
0.01
0.0853333
0.0853333
"Headset Earphone (@System32\\drivers\\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0\r\n;(JBL Charge 3))"
"Windows WDM-KS"
0
1
8000.0
14
0.01
0.01
0.0853333
0.0853333
"Headset Microphone (@System32\\drivers\\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0\r\n;(JBL Charge 3))"
"Windows WDM-KS"
1
0
8000.0
15
0.01
0.01
0.0853333
0.0853333
"Headset (@System32\\drivers\\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0\r\n;(ATH-ANC500BT))"
"Windows WDM-KS"
0
1
8000.0
16
0.01
0.01
0.0853333
0.0853333
"Headset (@System32\\drivers\\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0\r\n;(ATH-ANC500BT))"
"Windows WDM-KS"
1
0
8000.0
17
0.01
0.01
0.0853333
0.0853333
"Speakers ()"
"Windows WDM-KS"
0
2
44100.0
18
0.01
0.01
0.0853333
0.0853333
xxxxxxxxxx1
1
PortAudio.devices()Nakon što ste pronašli vaše uređaje, možete otkomentirati sljedeću ćeliju u kojoj se ulaz s mikrofona direktno prenosi na zvučnik. Nakon toga treba ponovo pokrenuti jezgru.
xxxxxxxxxx9
1
#=2
stream = PortAudioStream(2, 2)3
try4
# cancel with Ctrl-C5
write(stream, stream)6
finally7
close(stream)8
end9
=#Ukoliko želite snimiti svoj tekst, zamijenite mikrofon i izlaz s vašim uređajima, i izvedite sljedeće četiri čelije.
xxxxxxxxxx1
1
# stream = PortAudioStream("Microphone (BRIO 4K Stream Edit","Microsoft Sound Mapper - Output")xxxxxxxxxx2
1
# Namjestite duljinu snimke (nemojte pretjerivati)2
# buf = read(stream, 3s)xxxxxxxxxx2
1
# Zatvorite stream2
# close(stream)xxxxxxxxxx2
1
# Spremite vašu snimku2
# save("myvoice.ogg", buf)xxxxxxxxxx1
1
glas=load("myvoice.ogg")264600xxxxxxxxxx1
1
length(glas)44100.0xxxxxxxxxx1
1
glas.samplerateSampleBuf{Float32,2}xxxxxxxxxx1
1
typeof(glas)132300×2 Array{Float32,2}:
-0.000362047 -0.000493521
-0.00137746 -0.00141428
-0.00224675 -0.00219367
-0.00255539 -0.00244403
-0.0025107 -0.00236033
-0.00239858 -0.00221333
-0.00208273 -0.00188441
⋮
0.00212112 0.00213169
0.00104141 0.00105551
0.000218594 0.000235458
0.000212939 0.000245522
0.00111439 0.00114748
0.00236173 0.00236105xxxxxxxxxx1
1
glas.dataxxxxxxxxxx2
1
# Napravimo mono snimku2
glas_mono=similar(glas);44100.0xxxxxxxxxx4
1
begin2
glas_mono.data=sum(glas.data,dims=2)3
glas_mono.samplerate=glas.samplerate4
endxxxxxxxxxx1
1
save("myvoice_mono.ogg", glas_mono)132300×1 Array{Float32,2}:
-0.0008555677
-0.0027917377
-0.004440424
-0.0049994206
-0.0048710266
-0.004611913
-0.003967144
⋮
0.00425281
0.002096918
0.00045405142
0.00045846053
0.0022618691
0.0047227773xxxxxxxxxx1
1
glas_mono.dataxxxxxxxxxx1
1
glas_monoxxxxxxxxxx2
1
# Pogledajmo signal2
using Plotsxxxxxxxxxx4
1
begin2
S=glas_mono.data3
plot(S,label="Originalni signal")4
end0.0:2.2675908359095684e-5:3.0xxxxxxxxxx2
1
# Vrijeme2
T=range(0,3,length=length(S))xxxxxxxxxx2
1
# Plot u vremenu2
plot(T,S,xlabel="t (sec)",label="Originalni signal")B (generic function with 1 method)xxxxxxxxxx6
1
begin2
# Trapezna formula, približno. Računamo kosinusni i sinusni spektar3
using LinearAlgebra4
A(λ::Float64)=(cos.(λ*T)⋅S)*((T[end]-T[1])/(length(T)*π))5
B(λ::Float64)=(sin.(λ*T)⋅S)*((T[end]-T[1])/(length(T)*π))6
endxxxxxxxxxx1
# Nacrtajmo kosinusni i sinusni spektar i odlučimo koje frekvencije ćemo zadržati2
plot([A B],300,5000,layout=(2,1),label=["Kosinusni spektar" "Sinusni spektar"])-8.58264e-5
-0.00011846
-7.52201e-5
1.09887e-5
6.45053e-5
5.6946e-5
3.1058e-5
3.411e-5
5.64982e-5
5.52618e-5
2.03824e-5
-1.2551e-5
-1.64512e-5
-1.11372e-5
-3.09087e-5
-7.10462e-5
-9.18681e-5
-7.34278e-5
-4.11555e-5
-2.71351e-5
0.000119503
0.000134365
0.000115292
4.37664e-5
-5.22353e-5
-0.00010658
-7.02845e-5
4.29445e-5
0.000163861
0.000215551
xxxxxxxxxx10
1
begin2
# Ograničimo spektar, opet koristimo približnu formulu3
λ₀=600.04
λ₁=4500.05
step=0.56
Λ=range(λ₀,λ₁,step=step)7
# Ovo traje cca 1 minutu, ali se računa samo jednom8
Aλ=A.(Λ)9
Bλ=B.(Λ)10
endg (generic function with 1 method)xxxxxxxxxx2
1
# Rekonstruirajmo signal s odrezanim frekvencijama2
g(x::Float64)=(Aλ⋅cos.(x*Λ)+Bλ⋅sin.(x*Λ))*step0.0004776
0.000664933
0.000844558
0.00101462
0.00117337
0.00131917
0.00145053
0.00156609
0.00166467
0.00174525
0.00180701
0.00184931
0.00187173
0.00187403
0.00185619
0.00181839
0.00176102
0.00168467
0.00159013
0.00147836
-0.000157789
-0.000154486
-0.000148902
-0.000141117
-0.000131226
-0.000119341
-0.000105586
-9.0099e-5
-7.30288e-5
-5.45356e-5
xxxxxxxxxx1
1
G=g.(T)x
1
# Usporedimo grafički2
plot(T,[S G],layout=(2,1),label=["Originalni mono signal" "Odrezani mono signal"])xxxxxxxxxx6
1
begin2
# Spremimo signal s odrezanim frekvencijama i poslušajmo3
glas_mono_odrezan=deepcopy(glas_mono)4
glas_mono_odrezan.data[:,1]=map(Float32,G)5
save("myvoice_odrezan.ogg", glas_mono_odrezan)6
endxxxxxxxxxx1
1
glas_mono_odrezanEnter cell code...
xxxxxxxxxx1
1